from flask import Flask, request, jsonify
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLAlchemy(app)


app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:th@127.0.0.1/test'
class User(db.Model):
  __tablename__ = 'user'
  id = db.Column(db.Integer, primary_key = True)
  username = db.Column(db.String(40))
  password = db.Column(db.String(40))

@app.route('/', methods=['GET'])
def users():
  if request.method == 'GET':
    results = User.query.limit(10).offset(0).all()

    json_results = []
    for result in results:
      d = {'id': result.id,
           'username': result.username,
           'password': result.password}
      json_results.append(d)

    return jsonify(items=json_results)


if __name__ == '__main__':
  app.run(debug=True)
